﻿using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Threading.Tasks;
using AutoR.Messages;
using AutoR.Models;
using AutoR.Services;
using LiteDB;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Services;
using Xamarin.Forms;

namespace AutoR.ViewModels
{
	// Token: 0x02000051 RID: 81
	public class LoginViewModel : BindableBase, INavigationAware, INavigatedAware, INavigatingAware
	{
		// Token: 0x17000027 RID: 39
		// (get) Token: 0x0600010F RID: 271 RVA: 0x000408E6 File Offset: 0x0003EAE6
		private INavigationService NavigationService { get; }

		// Token: 0x17000028 RID: 40
		// (get) Token: 0x06000110 RID: 272 RVA: 0x000408EE File Offset: 0x0003EAEE
		private IPageDialogService PageDialogService { get; }

		// Token: 0x17000029 RID: 41
		// (get) Token: 0x06000111 RID: 273 RVA: 0x000408F6 File Offset: 0x0003EAF6
		public GameData Game
		{
			get
			{
				return Runtime.Game;
			}
		}

		// Token: 0x1700002A RID: 42
		// (get) Token: 0x06000112 RID: 274 RVA: 0x000408FD File Offset: 0x0003EAFD
		public DelegateCommand CDKCommand { get; }

		// Token: 0x1700002B RID: 43
		// (get) Token: 0x06000113 RID: 275 RVA: 0x00040905 File Offset: 0x0003EB05
		public DelegateCommand TryCommand { get; }

		// Token: 0x1700002C RID: 44
		// (get) Token: 0x06000114 RID: 276 RVA: 0x0004090D File Offset: 0x0003EB0D
		public DelegateCommand LoginCommand { get; }

		// Token: 0x1700002D RID: 45
		// (get) Token: 0x06000115 RID: 277 RVA: 0x00040915 File Offset: 0x0003EB15
		public DelegateCommand SaveUserCommand { get; }

		// Token: 0x1700002E RID: 46
		// (get) Token: 0x06000116 RID: 278 RVA: 0x0004091D File Offset: 0x0003EB1D
		public DelegateCommand OpenTBCommand { get; }

		// Token: 0x1700002F RID: 47
		// (get) Token: 0x06000117 RID: 279 RVA: 0x00040925 File Offset: 0x0003EB25
		public DelegateCommand ChangeLogCommand { get; }

		// Token: 0x17000030 RID: 48
		// (get) Token: 0x06000118 RID: 280 RVA: 0x0004092D File Offset: 0x0003EB2D
		public DelegateCommand ChangeBuiltinCommand { get; }

		// Token: 0x17000031 RID: 49
		// (get) Token: 0x06000119 RID: 281 RVA: 0x00040935 File Offset: 0x0003EB35
		public DelegateCommand ResourcesCommand { get; }

		// Token: 0x17000032 RID: 50
		// (get) Token: 0x0600011A RID: 282 RVA: 0x0004093D File Offset: 0x0003EB3D
		public DelegateCommand ResourcesAllCommand { get; }

		// Token: 0x17000033 RID: 51
		// (get) Token: 0x0600011B RID: 283 RVA: 0x00040945 File Offset: 0x0003EB45
		public DelegateCommand ClearDataCommand { get; }

		// Token: 0x17000034 RID: 52
		// (get) Token: 0x0600011C RID: 284 RVA: 0x0004094D File Offset: 0x0003EB4D
		public DelegateCommand ClearStatCommand { get; }

		// Token: 0x17000035 RID: 53
		// (get) Token: 0x0600011D RID: 285 RVA: 0x00040955 File Offset: 0x0003EB55
		public DelegateCommand CopyCDKCommand { get; }

		// Token: 0x17000036 RID: 54
		// (get) Token: 0x0600011E RID: 286 RVA: 0x0004095D File Offset: 0x0003EB5D
		// (set) Token: 0x0600011F RID: 287 RVA: 0x00040968 File Offset: 0x0003EB68
		public LoginConfig Config
		{
			[CompilerGenerated]
			get
			{
				return this.<Config>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<Config>k__BackingField, value))
				{
					return;
				}
				this.<Config>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.Config);
			}
		}

		// Token: 0x17000037 RID: 55
		// (get) Token: 0x06000120 RID: 288 RVA: 0x00040998 File Offset: 0x0003EB98
		// (set) Token: 0x06000121 RID: 289 RVA: 0x000409A0 File Offset: 0x0003EBA0
		public List<LoginConfig> UserList
		{
			[CompilerGenerated]
			get
			{
				return this.<UserList>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (object.Equals(this.<UserList>k__BackingField, value))
				{
					return;
				}
				this.<UserList>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.UserList);
			}
		}

		// Token: 0x17000038 RID: 56
		// (get) Token: 0x06000122 RID: 290 RVA: 0x000409D0 File Offset: 0x0003EBD0
		// (set) Token: 0x06000123 RID: 291 RVA: 0x000409D8 File Offset: 0x0003EBD8
		public bool IsBusy
		{
			[CompilerGenerated]
			get
			{
				return this.<IsBusy>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (this.<IsBusy>k__BackingField == value)
				{
					return;
				}
				this.<IsBusy>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.IsBusy);
			}
		}

		// Token: 0x17000039 RID: 57
		// (get) Token: 0x06000124 RID: 292 RVA: 0x00040A05 File Offset: 0x0003EC05
		// (set) Token: 0x06000125 RID: 293 RVA: 0x00040A10 File Offset: 0x0003EC10
		public bool IsNew
		{
			[CompilerGenerated]
			get
			{
				return this.<IsNew>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (this.<IsNew>k__BackingField == value)
				{
					return;
				}
				this.<IsNew>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.IsNew);
			}
		}

		// Token: 0x1700003A RID: 58
		// (get) Token: 0x06000126 RID: 294 RVA: 0x00040A3D File Offset: 0x0003EC3D
		// (set) Token: 0x06000127 RID: 295 RVA: 0x00040A48 File Offset: 0x0003EC48
		public bool IsNewPic
		{
			[CompilerGenerated]
			get
			{
				return this.<IsNewPic>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (this.<IsNewPic>k__BackingField == value)
				{
					return;
				}
				this.<IsNewPic>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.IsNewPic);
			}
		}

		// Token: 0x1700003B RID: 59
		// (get) Token: 0x06000128 RID: 296 RVA: 0x00040A75 File Offset: 0x0003EC75
		// (set) Token: 0x06000129 RID: 297 RVA: 0x00040A80 File Offset: 0x0003EC80
		public bool IsCheck
		{
			[CompilerGenerated]
			get
			{
				return this.<IsCheck>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (this.<IsCheck>k__BackingField == value)
				{
					return;
				}
				this.<IsCheck>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.IsNoCheck);
				this.OnPropertyChanged(<>PropertyChangedEventArgs.IsCheck);
			}
		}

		// Token: 0x1700003C RID: 60
		// (get) Token: 0x0600012A RID: 298 RVA: 0x00040AB8 File Offset: 0x0003ECB8
		// (set) Token: 0x0600012B RID: 299 RVA: 0x00040AC0 File Offset: 0x0003ECC0
		public bool IsDownload
		{
			[CompilerGenerated]
			get
			{
				return this.<IsDownload>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (this.<IsDownload>k__BackingField == value)
				{
					return;
				}
				this.<IsDownload>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.IsDownload);
			}
		}

		// Token: 0x1700003D RID: 61
		// (get) Token: 0x0600012C RID: 300 RVA: 0x00040AED File Offset: 0x0003ECED
		// (set) Token: 0x0600012D RID: 301 RVA: 0x00040AF8 File Offset: 0x0003ECF8
		public float DownloadProgress
		{
			[CompilerGenerated]
			get
			{
				return this.<DownloadProgress>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (this.<DownloadProgress>k__BackingField == value)
				{
					return;
				}
				this.<DownloadProgress>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.DownloadProgress);
			}
		}

		// Token: 0x1700003E RID: 62
		// (get) Token: 0x0600012E RID: 302 RVA: 0x00040B28 File Offset: 0x0003ED28
		public bool IsNoCheck
		{
			get
			{
				return !this.IsCheck;
			}
		}

		// Token: 0x1700003F RID: 63
		// (get) Token: 0x0600012F RID: 303 RVA: 0x00040B33 File Offset: 0x0003ED33
		// (set) Token: 0x06000130 RID: 304 RVA: 0x00040B3C File Offset: 0x0003ED3C
		public string CDKInfo
		{
			[CompilerGenerated]
			get
			{
				return this.<CDKInfo>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (string.Equals(this.<CDKInfo>k__BackingField, value, StringComparison.Ordinal))
				{
					return;
				}
				this.<CDKInfo>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.CDKInfo);
			}
		}

		// Token: 0x17000040 RID: 64
		// (get) Token: 0x06000131 RID: 305 RVA: 0x00040B6D File Offset: 0x0003ED6D
		// (set) Token: 0x06000132 RID: 306 RVA: 0x00040B78 File Offset: 0x0003ED78
		public string VersionName
		{
			[CompilerGenerated]
			get
			{
				return this.<VersionName>k__BackingField;
			}
			[CompilerGenerated]
			set
			{
				if (string.Equals(this.<VersionName>k__BackingField, value, StringComparison.Ordinal))
				{
					return;
				}
				this.<VersionName>k__BackingField = value;
				this.OnPropertyChanged(<>PropertyChangedEventArgs.VersionName);
			}
		}

		// Token: 0x06000133 RID: 307 RVA: 0x00040BAC File Offset: 0x0003EDAC
		public LoginViewModel(INavigationService navigationService, IPageDialogService pageDialogService)
		{
			this.<IsBusy>k__BackingField = true;
			LoginViewModel.<>c__DisplayClass88_0 CS$<>8__locals1 = new LoginViewModel.<>c__DisplayClass88_0();
			CS$<>8__locals1.pageDialogService = pageDialogService;
			base..ctor();
			CS$<>8__locals1.<>4__this = this;
			this.NavigationService = navigationService;
			this.PageDialogService = CS$<>8__locals1.pageDialogService;
			this.CDKCommand = new DelegateCommand(new Action(this.OnCDKCommandExecuted));
			this.TryCommand = new DelegateCommand(new Action(this.OnTryCommandExecuted));
			this.LoginCommand = new DelegateCommand(new Action(this.OnLoginCommandExecuted));
			this.ResourcesCommand = new DelegateCommand(new Action(this.OnResourcesCommandExecuted));
			this.ResourcesAllCommand = new DelegateCommand(new Action(this.OnResourcesAllCommandExecuted));
			this.ClearDataCommand = new DelegateCommand(delegate()
			{
				LoginViewModel.<>c__DisplayClass88_0.<<-ctor>b__0>d <<-ctor>b__0>d;
				<<-ctor>b__0>d.<>4__this = CS$<>8__locals1;
				<<-ctor>b__0>d.<>t__builder = AsyncVoidMethodBuilder.Create();
				<<-ctor>b__0>d.<>1__state = -1;
				AsyncVoidMethodBuilder <>t__builder = <<-ctor>b__0>d.<>t__builder;
				<>t__builder.Start<LoginViewModel.<>c__DisplayClass88_0.<<-ctor>b__0>d>(ref <<-ctor>b__0>d);
			});
			this.ClearStatCommand = new DelegateCommand(delegate()
			{
				LoginViewModel.<>c__DisplayClass88_0.<<-ctor>b__1>d <<-ctor>b__1>d;
				<<-ctor>b__1>d.<>4__this = CS$<>8__locals1;
				<<-ctor>b__1>d.<>t__builder = AsyncVoidMethodBuilder.Create();
				<<-ctor>b__1>d.<>1__state = -1;
				AsyncVoidMethodBuilder <>t__builder = <<-ctor>b__1>d.<>t__builder;
				<>t__builder.Start<LoginViewModel.<>c__DisplayClass88_0.<<-ctor>b__1>d>(ref <<-ctor>b__1>d);
			});
			this.CopyCDKCommand = new DelegateCommand(delegate()
			{
				LoginViewModel.<>c__DisplayClass88_0.<<-ctor>b__2>d <<-ctor>b__2>d;
				<<-ctor>b__2>d.<>4__this = CS$<>8__locals1;
				<<-ctor>b__2>d.<>t__builder = AsyncVoidMethodBuilder.Create();
				<<-ctor>b__2>d.<>1__state = -1;
				AsyncVoidMethodBuilder <>t__builder = <<-ctor>b__2>d.<>t__builder;
				<>t__builder.Start<LoginViewModel.<>c__DisplayClass88_0.<<-ctor>b__2>d>(ref <<-ctor>b__2>d);
			});
			this.OpenTBCommand = new DelegateCommand(delegate()
			{
				Device.OpenUri(new Uri("http://47.98.206.15"));
			});
			this.ChangeLogCommand = new DelegateCommand(delegate()
			{
				LoginViewModel.<>c__DisplayClass88_0.<<-ctor>b__4>d <<-ctor>b__4>d;
				<<-ctor>b__4>d.<>4__this = CS$<>8__locals1;
				<<-ctor>b__4>d.<>t__builder = AsyncVoidMethodBuilder.Create();
				<<-ctor>b__4>d.<>1__state = -1;
				AsyncVoidMethodBuilder <>t__builder = <<-ctor>b__4>d.<>t__builder;
				<>t__builder.Start<LoginViewModel.<>c__DisplayClass88_0.<<-ctor>b__4>d>(ref <<-ctor>b__4>d);
			});
			this.ChangeBuiltinCommand = new DelegateCommand(delegate()
			{
				LoginViewModel.<>c__DisplayClass88_0.<<-ctor>b__5>d <<-ctor>b__5>d;
				<<-ctor>b__5>d.<>4__this = CS$<>8__locals1;
				<<-ctor>b__5>d.<>t__builder = AsyncVoidMethodBuilder.Create();
				<<-ctor>b__5>d.<>1__state = -1;
				AsyncVoidMethodBuilder <>t__builder = <<-ctor>b__5>d.<>t__builder;
				<>t__builder.Start<LoginViewModel.<>c__DisplayClass88_0.<<-ctor>b__5>d>(ref <<-ctor>b__5>d);
			});
			this.SaveUserCommand = new DelegateCommand(delegate()
			{
				LoginViewModel.<>c__DisplayClass88_0.<<-ctor>b__6>d <<-ctor>b__6>d;
				<<-ctor>b__6>d.<>4__this = CS$<>8__locals1;
				<<-ctor>b__6>d.<>t__builder = AsyncVoidMethodBuilder.Create();
				<<-ctor>b__6>d.<>1__state = -1;
				AsyncVoidMethodBuilder <>t__builder = <<-ctor>b__6>d.<>t__builder;
				<>t__builder.Start<LoginViewModel.<>c__DisplayClass88_0.<<-ctor>b__6>d>(ref <<-ctor>b__6>d);
			});
			this.Config = (this.col.FindOne(Query.All(1)) ?? new LoginConfig());
			this.UserList = Runtime.ConfigDatabase.GetCollection<LoginConfig>("LoginUser").FindAll().ToList<LoginConfig>();
		}

		// Token: 0x06000134 RID: 308 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatedFrom(INavigationParameters parameters)
		{
		}

		// Token: 0x06000135 RID: 309 RVA: 0x00040D64 File Offset: 0x0003EF64
		public async void OnNavigatedTo(INavigationParameters parameters)
		{
			int num = 0;
			try
			{
				int num2 = await Xamarin.Forms.DependencyService.Get<ISystem>(DependencyFetchTarget.GlobalInstance).CheckAppVer();
				if (num2 > 0)
				{
					this.IsNew = true;
					if (num2 > 3)
					{
						this.isForce = true;
					}
				}
				this.VersionName = Xamarin.Forms.DependencyService.Get<ISystem>(DependencyFetchTarget.GlobalInstance).GetVersionName();
				MessagingCenter.Send<ServiceMessage>(new ServiceMessage("Start"), "Service");
			}
			catch (Exception obj)
			{
				num = 1;
			}
			object obj;
			if (num == 1)
			{
				Exception ex = (Exception)obj;
				await this.PageDialogService.DisplayAlertAsync("错误", "初始化失败，请重新打开！\n如果一直有此提示，请联系作者！", "OK");
				this.IsBusy = true;
			}
			obj = null;
			num = 0;
			try
			{
				string path = Xamarin.Forms.DependencyService.Get<ISystem>(DependencyFetchTarget.GlobalInstance).GetPersonalPath();
				Directory.CreateDirectory(Path.Combine(path, "Resource"));
				string name = Path.Combine(path, "Resource/list.txt");
				if (File.Exists(name))
				{
					string oldMD5 = LoginViewModel.GetMD5FromFile(name);
					using (WebClient client = new WebClient())
					{
						client.BaseAddress = "https://jianghanxia.gitee.io/pages/JPG/";
						await client.DownloadFileTaskAsync("Resource/list.txt", name);
					}
					WebClient client = null;
					if (LoginViewModel.GetMD5FromFile(name) != oldMD5)
					{
						this.IsNewPic = true;
					}
					else
					{
						using (StreamReader streamReader = new StreamReader(Path.Combine(path, "Resource/list.txt")))
						{
							string[] array = streamReader.ReadToEnd().Split(new char[]
							{
								'\n'
							});
							for (int i = 0; i < array.Length; i++)
							{
								if (!File.Exists(Path.Combine(path, array[i].Split(new char[]
								{
									','
								})[0])))
								{
									this.IsNewPic = true;
									break;
								}
							}
						}
					}
					oldMD5 = null;
				}
				else
				{
					this.IsNewPic = true;
					using (WebClient client = new WebClient())
					{
						client.BaseAddress = "https://jianghanxia.gitee.io/pages/JPG/";
						await client.DownloadFileTaskAsync("Resource/list.txt", name);
					}
					WebClient client = null;
				}
				path = null;
				name = null;
			}
			catch (Exception obj)
			{
				num = 1;
			}
			if (num == 1)
			{
				Exception ex2 = (Exception)obj;
				await this.PageDialogService.DisplayAlertAsync("错误", "初始化失败，请重新打开！\n如果一直有此提示，请联系作者！", "OK");
				this.IsBusy = true;
			}
			obj = null;
		}

		// Token: 0x06000136 RID: 310 RVA: 0x0004067F File Offset: 0x0003E87F
		public void OnNavigatingTo(INavigationParameters parameters)
		{
		}

		// Token: 0x06000137 RID: 311 RVA: 0x00040DA0 File Offset: 0x0003EFA0
		private void OnTryCommandExecuted()
		{
			this.Config.TryNum++;
			if (this.Config.TryNum > 20)
			{
				this.CDKInfo = "试用超过20次";
				return;
			}
			this.Game.IsTry = true;
			this.IsCheck = true;
			this.CDKInfo = "欢迎试用，本次试用30分钟后停止运行";
		}

		// Token: 0x06000138 RID: 312 RVA: 0x00040DFC File Offset: 0x0003EFFC
		private async void OnCDKCommandExecuted()
		{
			int num = 0;
			try
			{
				this.IsBusy = false;
				string text = await Runtime.Remote.CheckCDK(this.Config.CDK);
				string ck = text;
				if (ck.Split(new char[]
				{
					'|'
				}).Length == 3 && ck.Split(new char[]
				{
					'|'
				})[0] == "登录成功")
				{
					this.Game.CDKToken = ck.Split(new char[]
					{
						'|'
					})[2];
					await Runtime.Remote.Verify(this.Game.CDKToken);
					this.Game.CDK = this.Config.CDK;
					this.Game.CDKTime = DateTime.Now.AddMinutes(Convert.ToDouble(ck.Split(new char[]
					{
						'|'
					})[1]));
					this.CDKInfo = "验证成功，当前剩余时间：" + ck.Split(new char[]
					{
						'|'
					})[1] + "分钟";
					this.IsCheck = true;
					this.col.Upsert(this.Config);
				}
				else if (ck.StartsWith("操作失败"))
				{
					this.CDKInfo = ck;
				}
				else
				{
					this.CDKInfo = "发生错误，请稍后再试";
				}
				this.IsBusy = true;
				ck = null;
			}
			catch (Exception obj)
			{
				num = 1;
			}
			object obj;
			if (num == 1)
			{
				Exception ex = (Exception)obj;
				await this.PageDialogService.DisplayAlertAsync("错误", "验证失败，请重试！", "OK");
				this.IsBusy = true;
			}
			obj = null;
		}

		// Token: 0x06000139 RID: 313 RVA: 0x00040E38 File Offset: 0x0003F038
		private async void OnLoginCommandExecuted()
		{
			if (this.isForce)
			{
				await this.PageDialogService.DisplayAlertAsync("错误", "版本太老，请升级后使用", "OK");
			}
			else
			{
				IPAddress[] hostAddresses = Dns.GetHostAddresses("get.baibaoyun.com");
				if (hostAddresses.Length != 0 && (hostAddresses[0].ToString().Contains("240.0.0.") || hostAddresses[0].ToString() == "120.78.86.53"))
				{
					await this.PageDialogService.DisplayAlertAsync("错误", "你是盗版软件的受害者", "OK");
				}
				else
				{
					int num = 0;
					try
					{
						this.IsBusy = false;
						List<Server> list = await Runtime.Remote.ServerList();
						await this.Game.LoadConfigs(list[this.Config.Server]);
						if (this.Config.Server == 3 || this.Config.Server == 4)
						{
							LoginViewModel.<>c__DisplayClass94_0 CS$<>8__locals1 = new LoginViewModel.<>c__DisplayClass94_0();
							this.Game.ServerType = 2;
							List<Zone> s = (await this.Game.HLLogin(this.Config.UserName.Split(new char[]
							{
								'|'
							})[0], this.Config.UserName.Split(new char[]
							{
								'|'
							})[1], this.Config.Password)).ToList<Zone>();
							CS$<>8__locals1.ps = await this.PageDialogService.DisplayActionSheetAsync("选择服务器", null, null, (from i in s
							select i.name).ToArray<string>());
							Runtime.GameUrl = s.Single((Zone i) => i.name == CS$<>8__locals1.ps).host;
							this.Game.Username = this.Config.UserName.Split(new char[]
							{
								'|'
							})[0];
							this.Game.Password = this.Config.UserName.Split(new char[]
							{
								'|'
							})[1] + "|" + this.Config.Password;
							CS$<>8__locals1 = null;
							s = null;
						}
						else if (this.Config.Server == 2)
						{
							LoginViewModel.<>c__DisplayClass94_1 CS$<>8__locals2 = new LoginViewModel.<>c__DisplayClass94_1();
							this.Game.ServerType = 1;
							List<Zone> s = await this.Game.PassportLogin(this.Config.UserName, this.Config.Password);
							CS$<>8__locals2.ps = await this.PageDialogService.DisplayActionSheetAsync("选择服务器", null, null, (from i in s
							select i.name).ToArray<string>());
							Runtime.GameUrl = s.Single((Zone i) => i.name == CS$<>8__locals2.ps).host;
							this.Game.Username = this.Config.UserName;
							this.Game.Password = this.Config.Password;
							CS$<>8__locals2 = null;
							s = null;
						}
						else
						{
							LoginViewModel.<>c__DisplayClass94_2 CS$<>8__locals3 = new LoginViewModel.<>c__DisplayClass94_2();
							if (this.Config.Server == 5)
							{
								this.Game.ServerType = 3;
							}
							CS$<>8__locals3.a = await this.Game.HMLogin(this.Config.UserName, this.Config.Password);
							List<Zone> s = (from i in CS$<>8__locals3.a.Item1
							orderby i.id == CS$<>8__locals3.a.Item2 descending
							select i).ToList<Zone>();
							CS$<>8__locals3.ps = await this.PageDialogService.DisplayActionSheetAsync("选择服务器", null, null, s.Select(delegate(Zone i)
							{
								if (!(i.id == CS$<>8__locals3.a.Item2))
								{
									return i.name;
								}
								return i.name + " - 默认";
							}).ToArray<string>());
							Runtime.GameUrl = s.Single((Zone i) => i.name == CS$<>8__locals3.ps.Replace(" - 默认", "")).host;
							this.Game.Username = this.Config.UserName;
							this.Game.Password = this.Config.Password;
							CS$<>8__locals3 = null;
							s = null;
						}
						this.Game.IsLogin = true;
						this.Game.LoginTime = DateTime.Now;
						await this.Game.Login();
						this.col.Upsert(this.Config);
						if (this.UserList.Count((LoginConfig i) => i.UserName == this.Config.UserName && i.Server == this.Config.Server) == 0)
						{
							this.Config.Id = 0;
							Runtime.ConfigDatabase.GetCollection<LoginConfig>("LoginUser").Insert(this.Config);
						}
						this.Game.LoadTask();
						this.Game.StartService();
						await this.NavigationService.NavigateAsync("Navigation/Main");
						this.IsBusy = true;
					}
					catch (SysException obj)
					{
						num = 1;
					}
					catch (Exception obj)
					{
						num = 2;
					}
					int num2 = num;
					object obj;
					if (num2 != 1)
					{
						if (num2 == 2)
						{
							Exception ex = (Exception)obj;
							await this.PageDialogService.DisplayAlertAsync("错误", "登录失败，请重试！", "OK");
							this.IsBusy = true;
						}
					}
					else
					{
						SysException ex2 = (SysException)obj;
						await this.PageDialogService.DisplayAlertAsync("错误", ex2.Message, "OK");
						this.IsBusy = true;
					}
					obj = null;
				}
			}
		}

		// Token: 0x0600013A RID: 314 RVA: 0x00040E71 File Offset: 0x0003F071
		private void OnResourcesAllCommandExecuted()
		{
			Task.Factory.StartNew<Task>(async delegate()
			{
				int num = 0;
				try
				{
					this.IsBusy = false;
					this.IsDownload = true;
					this.DownloadProgress = 0f;
					string path = Xamarin.Forms.DependencyService.Get<ISystem>(DependencyFetchTarget.GlobalInstance).GetPersonalPath();
					using (WebClient client = new WebClient())
					{
						client.BaseAddress = "https://jianghanxia.gitee.io/pages/JPG/";
						await client.DownloadFileTaskAsync("Resource.zip", Path.Combine(path, "Resource.zip"));
					}
					WebClient client = null;
					this.DownloadProgress = 0.5f;
					Directory.Delete(path + "/Resource", true);
					ZipFile.ExtractToDirectory(Path.Combine(path, "Resource.zip"), path);
					File.Delete(Path.Combine(path, "Resource.zip"));
					this.IsDownload = false;
					this.IsBusy = true;
					this.IsNewPic = false;
					path = null;
				}
				catch (Exception obj)
				{
					num = 1;
				}
				object obj;
				if (num == 1)
				{
					Exception ex = (Exception)obj;
					await this.PageDialogService.DisplayAlertAsync("错误", "立绘下载失败，请重新下载！", "OK");
					this.IsDownload = false;
					this.IsBusy = true;
				}
				obj = null;
			});
		}

		// Token: 0x0600013B RID: 315 RVA: 0x00040E8A File Offset: 0x0003F08A
		private void OnResourcesCommandExecuted()
		{
			Task.Factory.StartNew<Task>(async delegate()
			{
				int num = 0;
				try
				{
					this.IsBusy = false;
					this.IsDownload = true;
					this.DownloadProgress = 0f;
					string path = Xamarin.Forms.DependencyService.Get<ISystem>(DependencyFetchTarget.GlobalInstance).GetPersonalPath();
					string text;
					using (StreamReader streamReader = new StreamReader(Path.Combine(path, "Resource/list.txt")))
					{
						text = streamReader.ReadToEnd();
					}
					string[] array = text.Split(new char[]
					{
						'\n'
					});
					int nc = array.Length;
					int i = 0;
					string[] array2 = array;
					for (int j = 0; j < array2.Length; j++)
					{
						string[] array3 = array2[j].Split(new char[]
						{
							','
						});
						string text2 = Path.Combine(path, array3[0]);
						if (File.Exists(text2))
						{
							if (array3[1] != LoginViewModel.GetMD5FromFile(text2))
							{
								using (WebClient client = new WebClient())
								{
									client.BaseAddress = "https://jianghanxia.gitee.io/pages/JPG/";
									Directory.CreateDirectory(Path.GetDirectoryName(text2));
									await client.DownloadFileTaskAsync(array3[0], text2);
								}
								WebClient client = null;
							}
						}
						else
						{
							using (WebClient client = new WebClient())
							{
								client.BaseAddress = "https://jianghanxia.gitee.io/pages/JPG/";
								Directory.CreateDirectory(Path.GetDirectoryName(text2));
								await client.DownloadFileTaskAsync(array3[0], text2);
							}
							WebClient client = null;
						}
						this.DownloadProgress = (float)i / (float)nc;
						i++;
					}
					array2 = null;
					this.IsDownload = false;
					this.IsBusy = true;
					this.IsNewPic = false;
					path = null;
				}
				catch (Exception obj)
				{
					num = 1;
				}
				object obj;
				if (num == 1)
				{
					Exception ex = (Exception)obj;
					await this.PageDialogService.DisplayAlertAsync("错误", "立绘下载失败，请重新下载！", "OK");
					this.IsDownload = false;
					this.IsBusy = true;
				}
				obj = null;
			});
		}

		// Token: 0x0600013C RID: 316 RVA: 0x00040EA4 File Offset: 0x0003F0A4
		public static string GetMD5FromFile(string fileName)
		{
			string result;
			using (FileStream fileStream = new FileStream(fileName, System.IO.FileMode.Open))
			{
				result = BitConverter.ToString(MD5.Create().ComputeHash(fileStream)).Replace("-", "").ToLower();
			}
			return result;
		}

		// Token: 0x040000A4 RID: 164
		private bool isForce;

		// Token: 0x040000A5 RID: 165
		private LiteCollection<LoginConfig> col = Runtime.ConfigDatabase.GetCollection<LoginConfig>();
	}
}
